package gc;

import java.lang.ref.PhantomReference;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;

public class WeakHashMapDemo {

    public static void main(String[] args) throws InterruptedException {


        Object obj = new Object();
        WeakHashMap weakHashMap = new WeakHashMap();
        weakHashMap.put(obj,"我是WeakHashMap");

        System.gc();
        TimeUnit.SECONDS.sleep(1);
        System.out.println("weakmap测试---------哈哈哈"+weakHashMap);


        Map map = new HashMap();
        Integer integer2 = new Integer(2);
        map.put(integer2,"第二个");
        integer2 = null;
        System.gc();
        TimeUnit.SECONDS.sleep(1);

        System.out.println("\"第二个\""+map);

    }
}
